package com.babel.util.tools;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class SponsCode {

	private static AtomicInteger diligenceCode = new AtomicInteger();
	
	private static Lock lock = new ReentrantLock();
	
	/**
	 * 生成数值累加
	 * @return
	 */
	public static String getDiligenceCode(){
		lock.lock();
		try {
			String i= diligenceCode.incrementAndGet()+"";
			if(i.length() < 4){
				if(i.length() == 1){
					return "00"+i;
				}else if(i.length() == 2){
					return "0"+i;
				}
			}
			return i.substring(i.length()-3, i.length());
		} finally {
			lock.unlock();
		}
	}
		
}
